package guoanmaker.operator.business.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.operator.business.model.OperatorFeedback;
import guoanmaker.operator.business.service.OperatorFeedbackServiceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(ApiController.OPERATOR_NEWTYPE)
public class OperatorFeedbackController {

	
	@Autowired
	private OperatorFeedbackServiceInterface operatorFeedbackServiceInterface;
	
	@ApiOperation(value = "用户反馈次数配置", notes = "用户反馈次数配置 ")
    @PostMapping(value = "/feedbackSetting")
    public AjaxJson feedbackSetting(String date,String frequency) {
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorFeedbackServiceInterface.FeedbackSetting(date, frequency));
			
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("保存失败");
		}
        return ajaxJson;
    }
	
	@ApiOperation(value = "查询用户反馈次数配置", notes = "查询用户反馈次数配置 ")
    @PostMapping(value = "/selectFeedbackSetting")
    public AjaxJson selectFeedbackSetting() {
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorFeedbackServiceInterface.selectFeedbackSetting());
			
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("保存失败");
		}
        return ajaxJson;
    }
	
	@ApiOperation(value = "新增用户反馈", notes = "新增用户反馈 ")
    @PostMapping(value = "/insertOperatorFeedback")
    public AjaxJson insertOperatorFeedback(String userId,String feedbackContext) {
		AjaxJson ajaxJson=new AjaxJson();
		try {
			Map<String,Object> map=operatorFeedbackServiceInterface.insertOperatorFeedback(userId, feedbackContext);
			if((int)map.get("stauts")==-1){
				ajaxJson.setSuccess(true).setStatus(220).setData(map.get("set"));
			}
			else{
				ajaxJson.setSuccess(true).setStatus(200).setData(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("保存失败");
		}
        return ajaxJson;
    }
	
	@ApiOperation(value = "查询用户反馈列表加分页", notes = "查询用户反馈列表加分页 ")
	@PostMapping(value = "/selectOperatorFeedbackPage")
	public AjaxJson selectOperatorFeedbackPage(Integer page,Integer size) {
		AjaxJson ajaxJson=new AjaxJson();
		try {
			Map<String, Object> map=operatorFeedbackServiceInterface.selectOperatorFeedbackPage(page, size);
			int a=(int) map.get("count");
			if(a>0){
				ajaxJson.setSuccess(true).setStatus(200).setData(map);
			}
			else{
				ajaxJson.setSuccess(true).setStatus(250).setData("没有数据");
			}
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
}
